package com.hyq.learn.common.exception;


import com.hyq.learn.common.exception.errorcode.ErrorCode;

public class SvcException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private ErrorCode errorCode;

    public static SvcException create(ErrorCode errorCode) {
        return new SvcException(errorCode, errorCode.getMessage());
    }

    public static SvcException create(ErrorCode errorCode, String errorMessage) {
        return new SvcException(errorCode, errorMessage);
    }

    public SvcException(ErrorCode errorCode, String errorMessage, Throwable cause) {
        super(errorMessage, cause);
        this.errorCode = errorCode;
    }

    public SvcException(ErrorCode errorCode) {
        this(errorCode, errorCode.getMessage());
    }

    public SvcException(ErrorCode errorCode, String errorMessage) {
        this(errorCode, errorMessage, null);
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(ErrorCode errorCode) {
        this.errorCode = errorCode;
    }
}
